﻿using System;
using System.Web.Mvc;
using WeiSha.Core.Templates;

namespace WeiSha.Core
{
	// Token: 0x0200002D RID: 45
	public class TemplateEngine : IViewEngine
	{
		// Token: 0x0600019F RID: 415 RVA: 0x0000BCD6 File Offset: 0x00009ED6
		public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache)
		{
			throw new NotImplementedException();
		}

		// Token: 0x060001A0 RID: 416 RVA: 0x0000BCE0 File Offset: 0x00009EE0
		public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
		{
			string absolutePath = controllerContext.HttpContext.Request.Url.AbsolutePath;
			bool flag = "404".Equals(viewName) || "500".Equals(viewName);
			if (flag)
			{
				string text = controllerContext.HttpContext.Request.RawUrl;
				bool flag2 = text.IndexOf("?") > -1;
				if (flag2)
				{
					text = text.Substring(0, text.LastIndexOf("?"));
				}
				string text2 = string.Empty;
				bool flag3 = text.IndexOf(".") > -1;
				if (flag3)
				{
					text2 = text.Substring(text.LastIndexOf(".") + 1);
				}
				bool flag4 = "css".Equals(text2, StringComparison.OrdinalIgnoreCase);
				if (flag4)
				{
					return new ViewEngineResult(new CssView(), this);
				}
				bool flag5 = "js".Equals(text2, StringComparison.OrdinalIgnoreCase);
				if (flag5)
				{
					return new ViewEngineResult(new JavascriptView(), this);
				}
			}
			string text3 = controllerContext.RouteData.Values["controller"].ToString();
			string text4 = controllerContext.RouteData.Values["action"].ToString();
			bool flag6 = viewName == "license";
			ViewEngineResult viewEngineResult;
			if (flag6)
			{
				viewEngineResult = new ViewEngineResult(new LicenseView(), this);
			}
			else
			{
				bool flag7 = viewName == "copyright";
				if (flag7)
				{
					viewEngineResult = new ViewEngineResult(new CopyrightView(), this);
				}
				else
				{
					viewEngineResult = new ViewEngineResult(new TemplateView(), this);
				}
			}
			return viewEngineResult;
		}

		// Token: 0x060001A1 RID: 417 RVA: 0x0000BE6B File Offset: 0x0000A06B
		public void ReleaseView(ControllerContext controllerContext, IView view)
		{
		}

		// Token: 0x060001A2 RID: 418 RVA: 0x0000BE70 File Offset: 0x0000A070
		public static TemplateBank Template(string device)
		{
			TemplateConfingItem templateConfingItem = WeiSha.Core.Template.ForAny(device);
			bool flag = templateConfingItem == null;
			if (flag)
			{
				throw new Exception("Template not found");
			}
			TemplateBank templateBank = null;
			PlateOrganInfo plateOrganInfo = PlateOrganInfo.Current();
			bool flag2 = plateOrganInfo == null;
			TemplateBank templateBank2;
			if (flag2)
			{
				templateBank2 = templateConfingItem.Default;
			}
			else
			{
				string text = string.Empty;
				bool flag3 = "web".Equals(device, StringComparison.CurrentCultureIgnoreCase);
				if (flag3)
				{
					text = plateOrganInfo.WebTemplateName;
				}
				bool flag4 = "mobi".Equals(device, StringComparison.CurrentCultureIgnoreCase);
				if (flag4)
				{
					text = plateOrganInfo.MobiTemplateName;
				}
				bool flag5 = !string.IsNullOrWhiteSpace(text);
				if (flag5)
				{
					templateBank = templateConfingItem.GetTemplate(text);
				}
				bool flag6 = templateBank == null;
				if (flag6)
				{
					templateBank = templateConfingItem.Default;
				}
				templateBank.OrganInfo = plateOrganInfo;
				templateBank2 = templateBank;
			}
			return templateBank2;
		}
	}
}
